home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libsurf / atmosphere.c next >
C/C++ Source or Header  |  1994-08-09  |  2KB  |  98 lines

  1. /*
  2.  * atmosphere.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * atmosphere.c,v 4.1 1994/08/09 08:01:18 explorer Exp
  17.  *
  18.  * atmosphere.c,v
  19.  * Revision 4.1  1994/08/09  08:01:18  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:12  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:40:02  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "atmosphere.h"
  30.  
  31. Atmosphere *
  32. AtmosCreate(data, method)
  33. char *data;
  34. void (*method)();
  35. {
  36.     Atmosphere *ef;
  37.  
  38.     ef = (Atmosphere *)Malloc(sizeof(Atmosphere));
  39.     ef->data = data;
  40.     ef->method = method;
  41.     ef->next = (Atmosphere *)0;
  42.     return ef;
  43. }
  44.  
  45. Atmosphere *
  46. AtmosphereCopy(atmos)
  47. Atmosphere *atmos;
  48. {
  49.     Atmosphere *res;
  50.  
  51.     if (atmos == (Atmosphere *)NULL)
  52.         return (Atmosphere *)NULL;
  53.     res = AtmosCreate(atmos->data, atmos->method);
  54.     res->next = AtmosphereCopy(atmos->next);
  55.     return res;
  56. }
  57.  
  58. Medium *
  59. MediumPush(index, statten, media)
  60. Float index, statten;
  61. Medium *media;
  62. {
  63.     Medium *new;
  64.  
  65.     new = (Medium *)Malloc(sizeof(Medium));
  66.     new->index = index;
  67.     new->statten = statten;
  68.     new->next = media;
  69.  
  70.     return new;
  71. }
  72.  
  73. void
  74. Atmospherics(effects, ray, dist, pos, color)
  75. Atmosphere *effects;
  76. Ray *ray;
  77. Float dist;
  78. Vector *pos;
  79. Color *color;
  80. {
  81.     Atmosphere *etmp;
  82.  
  83.     for (etmp = effects; etmp; etmp = etmp->next)
  84.         (*etmp->method)(etmp->data, ray, pos, dist, color);
  85. }
  86.  
  87. Float
  88. ExpAtten(dist, trans)
  89. Float dist, trans;
  90. {
  91.     Float atten;
  92.  
  93.     if (trans < EPSILON)
  94.         return 0.;
  95.     atten = LNHALF * dist / trans;
  96.     return (atten < -10. ? 0. : exp(atten));
  97. }
  98.